//
//  FamilyGroupFrame.m
//  二级评论
//
//  Created by Andrew on 2018/1/19.
//  Copyright © 2018年 Andrew. All rights reserved.
//

#import "FamilyGroupFrame.h"
#import "YMStringSize.h"
#import "FamilyGroup.h"
#import "SDPhotoGroup.h"

@implementation FamilyGroupFrame

#define LeftMargin 10
#define TopMargin 10

- (void)setModel:(FamilyGroup *)model
{
    _model = model;
    
    CGFloat ImageWH = 40;
    /** 头像 */
    self.iconViewF = CGRectMake(LeftMargin, TopMargin, ImageWH, ImageWH);
    
    /** 名称 */
    CGFloat nameH = 20;
    CGFloat nameW = [YMStringSize ym_sizeWithText:model.name font:LabelFontRegular(20) maxW:MAXFLOAT].width;
    CGFloat nameX = CGRectGetMaxX(self.iconViewF) + LeftMargin;
    CGFloat nameY = CGRectGetMidY(self.iconViewF) - nameH * 0.5;
    self.nameLabelF = CGRectMake(nameX, nameY, nameW, nameH);
    
    /** 内容 */
    CGFloat contentX = LeftMargin;
    CGFloat contentY = CGRectGetMaxY(self.iconViewF) + TopMargin;
    CGFloat contentW = SCREENWIDTH - LeftMargin * 2;
    CGSize contentSize = [YMStringSize ym_sizeWithText:model.shuoshuoText font:LabelFontRegular(16) maxW:contentW];
    self.shuoshuotextLabelF = (CGRect){{contentX,contentY},contentSize};
    
    //配图
    CGFloat commentY = CGRectGetMaxY(self.shuoshuotextLabelF) + TopMargin;
    if (model.pictures.count) {
        CGFloat picY = CGRectGetMaxY(self.shuoshuotextLabelF) + TopMargin;
        CGFloat picX = 0;
        CGSize picSize = [SDPhotoGroup sizeWithCount:model.pictures.count];
        self.photoGroupViewF = (CGRect){{picX,picY},picSize};
        
        commentY = CGRectGetMaxY(self.photoGroupViewF) + TopMargin;
    }
    
    /* 评论 */
    CGFloat commentX = LeftMargin;
    CGFloat commentW = SCREENWIDTH - LeftMargin * 2;
    CGFloat commentH = 0.0;
    CGFloat cellMargin = 5 + 5;
    
    if (model.replys.count) {
        
        for (NSInteger i = 0; i < model.replys.count; i++) {
            CGFloat h = [YMStringSize ym_sizeWithText:model.replys[i] font:LabelFontRegular(16) maxW:contentW].height + cellMargin;
            commentH += h;
        }
    }
    self.commentsBackViewF = CGRectMake(commentX, commentY, commentW, commentH);
    
    /** 时间 */
    CGFloat timeY = CGRectGetMaxY(self.commentsBackViewF) + TopMargin;
    CGFloat timeX = LeftMargin;
    CGSize timeSize = [YMStringSize ym_sizeWithText:model.time font:LabelFontRegular(14) maxW:MAXFLOAT];
    self.timeLabelF = (CGRect){{timeX ,timeY},timeSize};
    
    /* 评论按钮 */
    CGFloat btnW = 50;
    CGFloat btnH = 25;
    CGFloat btnX = SCREENWIDTH - btnW - LeftMargin * 2;
    CGFloat btnY = timeY;
    self.commentBtnF = CGRectMake(btnX, btnY, btnW, btnH);
    
    /* 分割线 */
    CGFloat lindViewY = CGRectGetMaxY(self.commentBtnF) + 10;
    self.lineViewF = CGRectMake(0, lindViewY, SCREENWIDTH, 1);
    
    /* origalView */
    CGFloat origalH = CGRectGetMaxY(self.lineViewF);
    self.origalViewF = CGRectMake(0, 0, SCREENWIDTH, origalH);
    
    /* cell的高度 */
    CGFloat cellHeight = CGRectGetMaxY(self.lineViewF);
    self.cellHeight = cellHeight;
}

@end
